package com.g4.shoppingsingle.controller;


import com.g4.shoppingsingle.pojo.DdKindType;
import com.g4.shoppingsingle.service.IDdKindTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * <p>
 * 型号列表 前端控制器
 * </p>
 *
 * @author admin
 * @since 2021-10-27
 */
@Slf4j
@RestController
@RequestMapping("/shoppingsingle/ddKindType")
public class DdKindTypeController {
    @Autowired
    private IDdKindTypeService ddKindTypeService;
    /**
     * 从liebiao.html 到 xiangqing.html , 并把pdId传过去
     * @param pdId
     * @return
     */
    @GetMapping("/tansTo/{pdId}")
    public ModelAndView tansTo(@PathVariable Integer pdId){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("xiangqing");    //页面的名字,不用写 .html, 会自动加上
        mv.addObject("pdId",pdId);
        //返回模型和视图(带上商品id,跳转页面)
        return mv;
    }

    /**
     * 通过商品id查询商品的所有型号信息
     * @param pdId
     * @return
     */
    @GetMapping("/{pdId}")
    public List<DdKindType> KindType(@PathVariable Integer pdId) {
        log.debug("接收到的参数pdId:" + pdId);
        if (pdId != null) {
            List<DdKindType> list = ddKindTypeService.getKindType(pdId);
            log.info("查询出来的结果集是--:"+ list);
            return list;
        }
        return null;
    }
}
